package edu.rit.varapp.utilities;

/**
 * Various helper methods for Strings, Integers, or Booleans.
 * @author Eric Kisner
 */
public class StringUtils {

    /**
     * Checks a string for null.
     * @param val The string to check for null value.
     * @return True if the string is null, else false.
     */
    public static boolean checkNull( String val ) {
        return (val == null);
    }

    public static boolean checkBoolean( String val ) {
        if( val.equals( "1" ) ) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Checks an Integer object for null.
     * @param val The Integer object to check for null value.
     * @return True if the Integer is null, else false.
     */
    public static boolean checkNull( Integer val ) {
        return (val == null);
    }

    /**
     * Checks a Boolean object for null.
     * @param val The Boolean object to check for null value.
     * @return True if the Boolean is null, else false.
     */
    public static boolean checkNull( Boolean val ) {
        return (val == null);
    }

    /**
     * Returns an empty string.
     */
    public static String emptyString() {
        return new String();
    }

    /**
     * Escapes special characters
     */
    public static String escapeSpecialCharacters( String input ) {
        input = input.replaceAll( "\\\\", "\\\\\\\\" );
        input = input.replaceAll( "=", "\\\\=" );
        input = input.replaceAll( "\\.", "\\\\." );
        input = input.replaceAll( ";", "\\\\;" );
        input = input.replaceAll( "\\\"", "\\\\\"" );
        input = input.replaceAll( "'", "\\\\'" );
        input = input.replaceAll( "%", "\\\\%" );
        input = input.replaceAll( "&", "\\\\&" );
        input = input.replaceAll( "`", "\\\\`" );
        return input;
    }
}
